Shader "dissolveOcclusion"
{
    Properties
    {
        _Albedo ("Albedo", 2D) = "white" {}
        _NoiseTex ("NoiseTexture", 2D) = "white" {}
        _ClipDistance("ClipDistance", Range(0,30)) = 10
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float2 uv : TEXCOORD0;
                float3 wroldPos : TEXCOORD1;
                float3 normalDir :TEXCOORD2; 
            };

            sampler2D _Albedo;
            float4 _Albedo_ST;

            sampler2D _NoiseTex;
            float4 _NoiseTex_ST;

            float _ClipDistance;

            v2f vert (appdata_full v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.texcoord, _Albedo);
                o.wroldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
                o.normalDir = UnityObjectToWorldNormal(v.normal);

                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                float distanceRamp = distance(i.wroldPos.xyz , _WorldSpaceCameraPos.xyz);

                //float distanceRamp = length(i.wroldPos.xyz - _WorldSpaceCameraPos.xyz);


                float checker = distanceRamp - _ClipDistance - tex2D(_NoiseTex, i.uv).r;
                clip(checker);

                // 灯光方向
                //float lightDirection = normalize(UnityWorldSpaceLightDir(i.worldPos));
                fixed3 worldLightDir = normalize(_WorldSpaceLightPos0.xyz);//获取 指向光源的方向
                float3 normalDirection = normalize(i.normalDir);
                float NdotL = saturate(dot(normalDirection,worldLightDir));
            
                fixed4 col = tex2D(_Albedo, i.uv) * NdotL;
                return col ;
            }
            ENDCG
        }
    }

    // Properties
    // {
    //     _Albedo ("Albedo", 2D) = "white" {}
    // }
    // SubShader
    //     {
    //         Tags { "RenderType"="Opaque+1" }

    //         CGPROGRAM

    //         #pragma surface surf Standard 

    //         sampler2D _Albedo;

    //         struct Input 
    //         {
    //             float2 uv_Albedo;
    //         };

    //         void surf (Input IN, inout SurfaceOutputStandard o) 
    //         {
    //                 o.Albedo =  tex2D(_Albedo, IN.uv_Albedo);
    //         }
    //     ENDCG
    //}

    FallBack "Diffuse"
}
